home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue56 / Clinic / ShellIconU.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-02-24  |  2.4 KB  |  98 lines

  1. unit ShellIconU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     dlgOpen: TOpenDialog;
  12.     imgSmall: TImage;
  13.     imgLarge: TImage;
  14.     imgSelected: TImage;
  15.     Label1: TLabel;
  16.     Label2: TLabel;
  17.     Label3: TLabel;
  18.     btnChooseFile: TButton;
  19.     lblDisplayName: TLabel;
  20.     lblFileType: TLabel;
  21.     lblExeType: TLabel;
  22.     procedure btnChooseFileClick(Sender: TObject);
  23.     procedure FormCreate(Sender: TObject);
  24.   private
  25.     { Private declarations }
  26.   public
  27.     { Public declarations }
  28.   end;
  29.  
  30. var
  31.   MainForm: TMainForm;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. uses
  38.   ShellAPI, ShlObj;
  39.  
  40. procedure TMainForm.btnChooseFileClick(Sender: TObject);
  41. var
  42.   FI: TSHFileInfo;
  43.   ExeType: DWord;
  44. const
  45.   MZ = $5A4D; //"MZ"
  46.   NE = $504E; //"NE"
  47.   PE = $4550; //"PE"
  48. begin
  49.   if dlgOpen.Execute then
  50.   begin
  51.     //Get display name and type description
  52.     SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI, SizeOf(FI),
  53.       SHGFI_DISPLAYNAME or SHGFI_TYPENAME);
  54.     lblDisplayName.Caption := FI.szDisplayName;
  55.     lblFileType.Caption := FI.szTypeName;
  56.  
  57.     //Get EXE type
  58.     ExeType := SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI, SizeOf(FI),
  59.       SHGFI_EXETYPE);
  60.     if ExeType = MZ then
  61.       lblExeType.Caption := 'MS-DOS .EXE, .COM or .BAT file'
  62.     else
  63.     if ExeType = PE then
  64.       lblExeType.Caption := 'Win32 console application'
  65.     else
  66.     if ((LoWord(ExeType) = NE) or
  67.         (LoWord(ExeType) = PE)) and
  68.        ((HiWord(ExeType) = $0300) or
  69.         (HiWord(ExeType) = $0350) or
  70.         (HiWord(ExeType) = $0400)) then
  71.       lblExeType.Caption := 'Windows application'
  72.     else
  73.       lblExeType.Caption := 'Not an executable file';
  74.  
  75.     //Get large icon
  76.     SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI,
  77.       SizeOf(FI), SHGFI_ICON or SHGFI_LARGEICON);
  78.     imgLarge.Picture.Icon.Handle := FI.hIcon;
  79.  
  80.     //Get small icon
  81.     SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI,
  82.       SizeOf(FI), SHGFI_ICON or SHGFI_SMALLICON);
  83.     imgSmall.Picture.Icon.Handle := FI.hIcon;
  84.  
  85.     //Get selected icon
  86.     SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI,
  87.       SizeOf(FI), SHGFI_ICON or SHGFI_SELECTED);
  88.     imgSelected.Picture.Icon.Handle := FI.hIcon;
  89.   end
  90. end;
  91.  
  92. procedure TMainForm.FormCreate(Sender: TObject);
  93. begin
  94.   btnChooseFile.Click
  95. end;
  96.  
  97. end.
  98.